import pytest
import logging
import allure
import utils.allure_step as allure_step
from utils.sele_Util import sele_Util
from time import sleep

logger = logging.getLogger()
sele_util = sele_Util('Chrome')


@pytest.fixture(scope='module', autouse=True)
def flow02_fixture(url_fixture):
    sele_util.open(url_fixture['Url'])
    yield
    sleep(3)
    sele_util.quit()


@pytest.fixture(scope='module', autouse=True)
def execl_fixture():
    file_url = 'data/TMS/客户信息功能测试.xlsx'
    yield file_url


@allure.suite('客户信息模块功能：登陆+新增客户+新增客户合同+合同操作+货物管理+常用地址+删除地址')
class TestFlow02:

    # 测试登录流程
    @allure.title('登录测试')
    @allure.story('进行登录测试')
    def test01_login(self, execl_fixture):
        logger.info('开始登录测试')
        sheet_name = '登录'
        allure_step.service(sele=sele_util, file_url=execl_fixture, sheet_name=sheet_name)

    @allure.title('新增客户')
    @allure.story('进行新增客户测试')
    def test02_create_client(self, execl_fixture):
        logger.info('开始进行新增客户测试')
        sheet_name = '新增客户'
        allure_step.service(sele=sele_util, file_url=execl_fixture, sheet_name=sheet_name)

    @allure.title('新增客户合同测试')
    @allure.story('进行新增客户合同测试')
    def test03_ask_pay(self, execl_fixture):
        logger.info('开始进行新增客户合同测试')
        sheet_name = '新增客户合同'
        allure_step.service(sele=sele_util, file_url=execl_fixture, sheet_name=sheet_name)

    @allure.title('合同操作测试')
    @allure.story('进行合同操作测试')
    def test04_refuse_pay(self, execl_fixture):
        logger.info('开始进行合同操作测试')
        sheet_name = '合同操作'
        allure_step.service(sele=sele_util, file_url=execl_fixture, sheet_name=sheet_name)

    @allure.title('货物管理测试')
    @allure.story('进行货物管理测试')
    def test05_reapply_pay(self, execl_fixture):
        logger.info('开始进行货物管理测试')
        sheet_name = '货物管理'
        allure_step.service(sele=sele_util, file_url=execl_fixture, sheet_name=sheet_name)

    @allure.title('常用地址测试')
    @allure.story('进行常用地址测试')
    def test06_pay_verify(self, execl_fixture):
        logger.info('开始常用地址测试')
        sheet_name = '常用地址'
        allure_step.service(sele=sele_util, file_url=execl_fixture, sheet_name=sheet_name)

    @allure.title('删除客户测试')
    @allure.story('进行删除客户测试')
    def test07_income_verify(self, execl_fixture):
        logger.info('开始删除客户测试')
        sheet_name = '删除客户'
        allure_step.service(sele=sele_util, file_url=execl_fixture, sheet_name=sheet_name)
